{extend name="public:layout" /}
{block name="title"}编辑配送{/block}
{block name="head"}
{:widget('common/Form/icheckRes')}
{:widget('common/Form/validRes')}
<script src="/public/plugins/template/template.js"></script>
{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index')}"> 配送列表</a></li>
                <li class="active">编辑配送</li>
            </ol>
        </div>
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form">

                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">配送名称</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入配送名称"
                               name="delivery_name" value="{$info.delivery_name}" datatype="*"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">运费设置</label>

                    <div class="col-sm-4">
                        <select class="form-control" id="deliveryType" name="delivery_type">
                            <option value="0" {eq name="info.delivery_type" value="0"}selected{/eq}>不设置运费(免费)</option>
                            <option value="1" {eq name="info.delivery_type" value="1"}selected{/eq}>设置固定运费</option>
                            <option value="2" {eq name="info.delivery_type" value="2"}selected{/eq}>按重量设置运费</option>
                        </select>
                    </div>
                </div>
                <div id="typeHtml"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">促销设置</label>

                    <div class="col-sm-4">
                        <select class="form-control" id="promotion" name="delivery_promotion_type">
                            <option value="0" {eq name="info.delivery_promotion_type" value="0"}selected{/eq}>不启用促销</option>
                            <option value="1" {eq name="info.delivery_promotion_type" value="1"}selected{/eq}>满免运费</option>
                            <option value="2" {eq name="info.delivery_promotion_type" value="2"}selected{/eq}>满减运费</option>
                        </select>
                    </div>
                </div>
                <div id="promotionHtml"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">是否默认</label>
                    <div class="col-sm-4">
                        <label class="radio-inline i-checks">
                            <input type="radio" name="is_default" value="1" {eq name="info.is_default" value="1"}checked{/eq}/> 是
                        </label>
                        <label class="radio-inline i-checks">
                            <input type="radio" name="is_default" value="0" {eq name="info.is_default" value="0"}checked{/eq}/> 否
                        </label>
                    </div>
                    <label class="col-sm-2 control-label">是否启用</label>
                    <div class="col-sm-4">
                        <label class="radio-inline i-checks">
                            <input type="radio" name="status" value="1" {eq name="info.status" value="1"}checked{/eq}/> 是
                        </label>
                        <label class="radio-inline i-checks">
                            <input type="radio" name="status" value="0" {eq name="info.status" value="0"}checked{/eq} /> 否
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary"
                                onclick="ajaxSubForm();" type="submit">
                            保存内容
                        </button>
                        <a href="{:url('index')}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script id="deliveryType0" type="text/html"></script>
<script id="deliveryType1" type="text/html">
    <div class="form-group">
        <label class="col-sm-2 control-label">运费设置</label>
        <div class="col-sm-4">
            <div class="input-group">
                {eq name="info.delivery_type" value="1"}
                <input type="text" class="form-control" name="delivery_money" value="{$info.delivery_money}" />
                {else/}
                <input type="text" class="form-control" name="delivery_money" value="" />
                {/eq}
                <span class="input-group-addon">元</span>
            </div>
        </div>
    </div>
</script>
<script id="deliveryType2" type="text/html">
    <div class="form-group">
        <label class="col-sm-2 control-label">运费设置</label>
        <div class="col-sm-2">
            <div class="input-group">
                <span class="input-group-addon">首重</span>
                {eq name="info.delivery_type" value="2"}
                <input type="text" class="form-control" name="delivery_weight_calc[first_weight]" value="{$info.delivery_weight_calc.first_weight}" />
                {else/}
                <input type="text" class="form-control" name="delivery_weight_calc[first_weight]" />
                {/eq}
                <span class="input-group-addon">g</span>
            </div>
        </div>
        <div class="col-sm-3">
            <div class="input-group">
                <span class="input-group-addon">首重运费</span>
                {eq name="info.delivery_type" value="2"}
                <input type="text" class="form-control" name="delivery_weight_calc[first_fright]" value="{$info.delivery_weight_calc.first_fright}" />
                {else/}
                <input type="text" class="form-control" name="delivery_weight_calc[first_fright]" />
                {/eq}
                <span class="input-group-addon">元</span>
            </div>
        </div>
        <div class="col-sm-2">
            <div class="input-group">
                <span class="input-group-addon">续重</span>
                {eq name="info.delivery_type" value="2"}
                <input type="text" class="form-control" name="delivery_weight_calc[second_weight]" value="{$info.delivery_weight_calc.second_weight}" />
                {else/}
                <input type="text" class="form-control" name="delivery_weight_calc[second_weight]" />
                {/eq}
                <span class="input-group-addon">g</span>
            </div>
        </div>
        <div class="col-sm-3">
            <div class="input-group">
                <span class="input-group-addon">续重运费</span>
                {eq name="info.delivery_type" value="2"}
                <input type="text" class="form-control" name="delivery_weight_calc[second_fright]" value="{$info.delivery_weight_calc.second_fright}" />
                {else/}
                <input type="text" class="form-control" name="delivery_weight_calc[second_fright]" />
                {/eq}
                <span class="input-group-addon">元</span>
            </div>
        </div>
    </div>
</script>
<script id="promotion0" type="text/html"></script>
<script id="promotion1" type="text/html">
    <div class="form-group">
        <label class="col-sm-2 control-label">促销设置</label>
        <div class="col-sm-4">
            <div class="input-group">
                <span class="input-group-addon">满</span>
                {eq name="info.delivery_promotion_type" value="1"}
                <input type="text" class="form-control" name="delivery_promotion_rule[price]" value="{$info.delivery_promotion_rule.price}" />
                {else/}
                <input type="text" class="form-control" name="delivery_promotion_rule[price]" />
                {/eq}
                <span class="input-group-addon">元免运费</span>
            </div>
        </div>
    </div>
</script>
<script id="promotion2" type="text/html">
    <div class="form-group">
        <label class="col-sm-2 control-label">促销设置</label>
        <div class="col-sm-4">
            <div class="input-group">
                <span class="input-group-addon">满</span>
                {eq name="info.delivery_promotion_type" value="2"}
                <input type="text" class="form-control" name="delivery_promotion_rule[price]" value="{$info.delivery_promotion_rule.price}" />
                {else/}
                <input type="text" class="form-control" name="delivery_promotion_rule[price]" />
                {/eq}
                <span class="input-group-addon">元</span>
            </div>
        </div>
        <div class="col-sm-4">
            <div class="input-group">
                <span class="input-group-addon">减</span>
                {eq name="info.delivery_promotion_type" value="2"}
                <input type="text" class="form-control" name="delivery_promotion_rule[fright]" value="{$info.delivery_promotion_rule.fright}" />
                {else/}
                <input type="text" class="form-control" name="delivery_promotion_rule[fright]" />
                {/eq}
                <span class="input-group-addon">元</span>
            </div>
        </div>
    </div>
</script>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        iCheck();
        $('#deliveryType').change(function () {
            var type = $(this).val();
            var html = template('deliveryType'+type);
            $('#typeHtml').html(html);
        });
        $('#promotion').change(function () {
            var value = $(this).val();
            var html = template('promotion'+value);
            $('#promotionHtml').html(html);
        })
        $("#deliveryType").trigger("change");
        $("#promotion").trigger("change");
    })
</script>
{/block}